package cn.rubintry.bug.hunting.activity

import android.app.Dialog
import android.content.Intent
import android.view.View
import cn.rubintry.bug.common.base.BaseActivity
import cn.rubintry.bug.hunting.databinding.ActivitySettingBinding
import cn.rubintry.bug.hunting.common.event.LogoutEvent
import cn.rubintry.bug.hunting.common.extension.visible
import cn.rubintry.bug.hunting.common.manager.UserManager
import com.lxj.xpopup.XPopup
import org.greenrobot.eventbus.EventBus

class SettingActivity : BaseActivity<ActivitySettingBinding>(), View.OnClickListener {
    override fun bindingClazz(): Class<ActivitySettingBinding> {
        return ActivitySettingBinding::class.java
    }

    override fun getActivityParams() {

    }

    override fun initView() {
        binding?.imgBack?.setOnClickListener(this)
        binding?.tvExitLogin?.visible = UserManager.getInstance().isLogin()
        binding?.tvExitLogin?.setOnClickListener(this)
    }

    override fun observeData() {

    }

    override fun onNetWorkError(msg: String?) {

    }

    override fun onClick(v: View?) {
        when(v){
            binding?.imgBack -> {
                finish()
            }

            binding?.tvExitLogin -> {
//                if(!UserManager.getInstance().isLogin()){
//                    startActivity(Intent(this, LoginActivity::class.java))
//                    return
//                }
//                IOSMessageDialog.Builder(this)
//                    .setMessage("确定要退出吗？")
//                    .setPositiveButton("确定") {
//                        UserManager.getInstance().logout()
//                        EventBus.getDefault().post(LogoutEvent())
//                        finish()
//                    }
//                    .setNegativeButton("取消") { }
//                    .create()
//                    .show()
                XPopup.Builder(this)
                    .asConfirm("退出登录", "确定要退出吗？") {
                        UserManager.getInstance().logout()
                        EventBus.getDefault().post(LogoutEvent())
                        finish()
                    }.show()
            }
        }
    }

}